package com.ssyt.hiring.web.action;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ssyt.cdp.common.Constants;
import com.ssyt.cdp.common.PageModel;
import com.ssyt.hiring.entity.PositionEntity;
import com.ssyt.hiring.web.service.PositionService;

@Controller
@Scope("prototype")
public class PositionAction extends CommonAction {

	@Autowired
	private PositionService positionService;
	private PageModel<PositionEntity> pageModel;
	private PositionEntity position;

	private int pageNo;
	private int pageSize;
	private String queryStr;
	private int positionId;

	/**
	 * 分页查询全部职位信息
	 * 
	 * @return
	 */
	public String listAll() {
		if (pageNo == 0) {
			pageNo = Constants.FIRST_PAGE;
		}
		if (pageSize == 0) {
			pageSize = Constants.DEFAULT_PAGE_SIZE;
		}
		pageModel = positionService.listAll(queryStr, pageNo, pageSize);
		return "listAll";
	}

	/**
	 * 删除职位信息
	 * 
	 * @return
	 */
	public String deleteposition() {
		positionService.deleteposition(positionId);
		return "positionAll";
	}

	/**
	 * 修改前查询职位信息
	 */
	public String getInfoPosition() {
		position = positionService.getInfoPosition(positionId);
		return "positioninfo";
	}

	public String positionInfoShow() {
		position = positionService.getInfoPosition(positionId);
		return "positioninfoshow";
	}

	/**
	 * 修改发布职位信息
	 * 
	 * @return
	 */
	public String updatePosition() {
		position.setReleaseTime(new Date());
		positionService.updatePosition(position);
		return "positionAll";
	}

	/**
	 * 发布职位
	 * 
	 * @return
	 */
	public String addposition() {
		positionService.addposition(position);
		return "positionAll";
	}

	/**
	 * 检查发布的职位名是否重复
	 */
	public void checkPositionName() {
		System.out.println(position.getName());
		boolean result = positionService.checkPositionName(position.getName());
		print(result + "");
	}

	public PositionEntity getPosition() {
		return position;
	}

	public void setPosition(PositionEntity position) {
		this.position = position;
	}

	public PositionService getPositionService() {
		return positionService;
	}

	public void setPositionService(PositionService positionService) {
		this.positionService = positionService;
	}

	public PageModel<PositionEntity> getPageModel() {
		return pageModel;
	}

	public void setPageModel(PageModel<PositionEntity> pageModel) {
		this.pageModel = pageModel;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPositionId() {
		return positionId;
	}

	public void setPositionId(int positionId) {
		this.positionId = positionId;
	}

	public String getQueryStr() {
		return queryStr;
	}

	public void setQueryStr(String queryStr) {
		this.queryStr = queryStr;
	}

}
